﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace System.Windows.Media.DirectShow.Filters
{
    public class ElementCaptureSource : BaseFilter
    {

        private ElementCaptureSourceAsyncPin outputPin;

        public ElementCaptureSource()
        {
            outputPin = new ElementCaptureSourceAsyncPin(this);
            this.Pins.Add(outputPin);
        }

        public override string Name
        {
            get { return "Element Capture Filter"; }
        }

        public void SetElement(UIElement element, double framesPerSecond)
        {
            if (element == null)
                throw new ArgumentNullException("element");

            WriteableBitmap bitmap = new WriteableBitmap(element, null);
            this.outputPin.SetCapture(element, bitmap.PixelWidth, bitmap.PixelHeight, TimeSpan.FromMilliseconds(1000 / framesPerSecond));
        }
    }
}
